package cst.a931xmc.yuejian20.Fragment.Train;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import cst.a931xmc.yuejian20.Adapter.TrainAdapter;
import cst.a931xmc.yuejian20.Bean.TrainBean;
import cst.a931xmc.yuejian20.Listener.Listener;
import cst.a931xmc.yuejian20.Model.TrainModel;
import cst.a931xmc.yuejian20.R;

public class HighFragment extends Fragment {
    private RecyclerView recyclerView;
    private TrainAdapter adapter;
    private RecyclerView.LayoutManager layoutManager;
    private Listener<List<TrainBean>> listener;
    private TrainModel model;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_tlow,container,false);
        initViews(view);
        initData();
        model = new TrainModel();
        model.getList(3,listener);
        return view;
    }

    public void initViews(View view){
        recyclerView = view.findViewById(R.id.rv_low);
        adapter = new TrainAdapter(getActivity());
        layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
    }

    public void initData(){
        listener = new Listener<List<TrainBean>>() {
            @Override
            public void onResponse(List<TrainBean> list) {
                recyclerView.setAdapter(adapter);
                adapter.setList(list);
            }

            @Override
            public void onFail(String message) {

            }
        };
    }
}

